# -*- coding:utf-8 _*-  
import requests
from fake_useragent import UserAgent

# 全局重复次数
try_count = 0


# 采用useragent访问网站
def get(url):
    try:
        res = requests.get(url, headers={'User-Agent': UserAgent().random}, timeout=5, verify=False)
        res.encoding = 'utf-8'
        response = res.text
        return response
    except:
        response = None
        return response


# 调用代理ip
def _ip():
    ip = ''
    return ip


# 采用useragent以及代理ip访问网站
def proxy_get(url):
    global try_count
    try_count += 1
    ip = _ip()
    if ip is not None:
        proxy = {"http": "http://{}".format(ip), "https": "https://{}".format(ip)}
        try:
            res = requests.get(url, headers={'User-Agent': UserAgent().random}, proies=proxy, timeout=5, verify=False)
            res.encoding = 'utf-8'
            return res.text
        except:
            return None
    else:
        if try_count <= 5:
            print('{} times try to get proxy ip'.format(try_count))
            return proxy_get(url)
        else:
            print('get proxy ip filed')
            return None


if __name__ == '__main__':
    pass
